package com.simulador.mainframe;

import java.util.ArrayList;

public abstract class MathUtils {
	
	private static RandomGenerator r = new RandomGenerator();
	
	/** Calculates the mean of the input values */
	public static float mean(ArrayList<Integer> data) {
		float sum = 0.0f;
		
		for (Integer i : data) {
			sum += i;
		}
		
		return sum / data.size();
	}
	
	/** Calculates the variance of the input values */
	public static float variance(ArrayList<Integer> data) {
		float mean = mean(data);
		float sum = 0.0f;
		
		for (Integer i : data) {
			sum += (i - mean) * (i - mean);
		}
		
		return sum / (data.size() - 1);
	}
	
	/** Returns an uniform random variable between inf and sup */
	public static float generateUniform(float inf, float sup) {
		float n = r.rand(5);
		return n * (sup - inf) + inf;
	}
}
